package cn.easy.rpc.controller;

import cn.easy.rpc.annotations.RpcReference;
import cn.easy.rpc.common.CartService;
import cn.easy.rpc.common.OrderService;
import cn.easy.rpc.common.UserService;
import cn.easy.rpc.context.RpcContext;
import cn.easy.rpc.core.ServiceRegistrar;
import cn.easy.rpc.dto.Cart;
import cn.easy.rpc.dto.Commodity;
import cn.easy.rpc.dto.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zwb
 * @create 2020-09-17 21:42
 **/
@RestController
public class RpcController {

    @RpcReference(appName = "provider",schema = "user")
    private UserService userService;


    @RpcReference(appName = "provider",schema = "cart")
    private CartService cartService;


    @RpcReference(appName = "provider",schema = "order")
    private OrderService orderService;

    @RequestMapping("registrarList")
    private List<ServiceRegistrar> getRegistrar(){
        return RpcContext.getInstance().getDependService();
    }

    @RequestMapping("getUser")
    private User getUser(){
        return userService.getUser("zwb",21);
    }

    @RequestMapping("userList")
    private List<User> userList(){
        return userService.userList();
    }


    @RequestMapping("insertCart")
    private boolean insertCart(){
        return cartService.insertCart(new Cart());
    }

    @RequestMapping("getOrderId")
    private String getOrderId(){
        return orderService.getOrderId();
    }

    @RequestMapping("commodityList")
    public List<Commodity> commodityList(){
        return cartService.commodityList();
    }
}
